package szkeleton;

import java.awt.Graphics2D;
import java.awt.Point;

public class TileView implements Paintable
{
	private Tile tile;
	private int elementwidth;
	
	public TileView(Tile t)
	{
		tile=t;
	}
	
	public int getElementWidth()
	{
		return elementwidth;
	}

	@Override
	public void Paint(Graphics2D g, Point start, Point end) 
	{
		if (!tile.isEmpty())
		{
		elementwidth = (end.x-start.x)/tile.getDimension().x;
		for (int x=0;x<tile.getDimension().x;x++)
		{
			for (int y=0;y<tile.getDimension().y;y++)
			{
				
				
				switch (tile.getElementforView(new Point(x,y)).getTipe())
				{
				case wp: 
					{
						WhitePointView wpv = new WhitePointView((WhitePoint)tile.getElementforView(new Point(x,y)));
						wpv.Paint(g, new Point(start.x+x*elementwidth, start.y+y*elementwidth), new Point(start.x+x*elementwidth+elementwidth, start.y+y*elementwidth+elementwidth));						
						break;
					}
				case bp: 
					{
						BlackPointView bpv = new BlackPointView((BlackPoint)tile.getElementforView(new Point(x,y)));
						bpv.Paint(g, new Point(start.x+x*elementwidth, start.y+y*elementwidth), new Point(start.x+x*elementwidth+elementwidth, start.y+y*elementwidth+elementwidth));
						break;
					}
				case k: 
					{
						KeyView kv = new KeyView((Key)tile.getElementforView(new Point(x,y)));
						kv.Paint(g, new Point(start.x+x*elementwidth, start.y+y*elementwidth), new Point(start.x+x*elementwidth+elementwidth, start.y+y*elementwidth+elementwidth));
						break;
					}
				case d: 
					{
						DoorView dv = new DoorView((Door)tile.getElementforView(new Point(x,y)));
						dv.Paint(g, new Point(start.x+x*elementwidth, start.y+y*elementwidth), new Point(start.x+x*elementwidth+elementwidth, start.y+y*elementwidth+elementwidth));
						break;
					}
					
				}
				
				g.drawRect(start.x+x*elementwidth, start.y+y*elementwidth, elementwidth, elementwidth);
				
			}
		}
		}
	}

}
